package com.ydd.moudle.message;

import android.content.Intent;
import android.os.Bundle;
import android.os.PersistableBundle;
import android.support.annotation.Nullable;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.text.TextUtils;
import android.view.View;
import android.widget.TextView;
import android.widget.Toast;

import com.google.gson.Gson;
import com.ydd.R;
import com.ydd.adapter.SystemMsgAdapter;
import com.ydd.base.BaseActivity;
import com.ydd.model.mina.MinaMessage;
import com.ydd.model.mina.MinaModel;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by tao on 17-3-23.
 * 显示接收到的系统消息
 */

public class MessageActivity extends BaseActivity {
    public static final String DATA_LIST = "data_list";
    public static final String TYPE = "type";
    public static final int UNREAD = 1;
    public static final int ZAN = 2;
    public static final int IMOOC = 3;
    /**
     * UI
     */
    private RecyclerView mRecycleView;
    private TextView mSysMessageView;
    /**
     * Data
     */
    private int msgType;
    private List<MinaMessage> mLists;
    private SystemMsgAdapter mAdapter;
    private String data;
    private MinaModel mData;


    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_message_layout);

        initData();
        initView();
    }

    private void initData() {
        Intent intent = getIntent();
        msgType = intent.getIntExtra(TYPE, 3);
        data = intent.getStringExtra(DATA_LIST);
//        mLists = (List<MinaMessage>) intent.getSerializableExtra(DATA_LIST);
    }

    private void initView() {
        switch (msgType) {
            case UNREAD:
                initHeaderView(getString(R.string.liuyan_message), true);
                break;
            case ZAN:
                initHeaderView(getString(R.string.receive_zan_message), true);
                break;
            case IMOOC:
                initHeaderView(getString(R.string.xitong_message), true);
                break;
        }
        mSysMessageView = (TextView) findViewById(R.id.sys_message);
        if (!TextUtils.isEmpty(data)){
            mSysMessageView.setVisibility(View.VISIBLE);

            mSysMessageView.setText(data);
        }

        mRecycleView = (RecyclerView) findViewById(R.id.recycle_view);
        mAdapter = new SystemMsgAdapter(this, mLists);
        mRecycleView.setLayoutManager(new LinearLayoutManager(this));
        mRecycleView.setAdapter(mAdapter);
    }

}
